package com.cskaoyan.controller;

import com.cskaoyan.bean.*;
import com.cskaoyan.model.bo.GoodsBO;
import com.cskaoyan.model.bo.ShangJiaBO;
import com.cskaoyan.service.GoodsService;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/goods")
public class GoodsController{
    @Autowired
    GoodsService goodsService;

    @RequestMapping("list")
    public BaseRespVo list(Integer page,Integer limit ,String sort,String order,Integer goodsSn,String name){
        BaseListData data = null;
        if(goodsSn == null && name == null){
             data = goodsService.list(page,limit,sort,order);
        }else{
            data = goodsService.list2(page,limit,sort,order,goodsSn,name);
        }
        return BaseRespVo.ok(data);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) throws JsonProcessingException {
        GoodsEdit data = goodsService.detail(id);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Goods goods){
        int res = goodsService.delete(goods);
        if(res == 1){
            return BaseRespVo.ok();
        }else{
            return BaseRespVo.fail("失败了");
        }
    }
//    @RequestMapping("create")
//    public BaseRespVo create(@RequestBody Goods_attribute goods_attribute,
//                             GoodsBO goodsBO,
//                             Goods_product goods_product,
//                             Goods_specification goods_specification){
//        int res = goodsService.create(goods_attribute,goodsBO,goods_product,goods_specification);
//        if(res == 1){
//            return BaseRespVo.ok();
//        }else{
//            return BaseRespVo.fail("添加失败了");
//        }
//    }
}
